package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Calendar;

@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/")
    public String index(Model model) {
        return toIndexPage(model, 0, 2);
    }

    @RequestMapping("/list")
    public String toIndexPage(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        Page<Article> articlePage = articleService.listArticlesByPage(pageNum, pageSize);
        model.addAttribute("articlePage", articlePage);
        return "client/index";
    }


}
